﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.Accessctl.Entitys
{
    /// <summary>
    /// 权限管理
    /// </summary>
    [SugarTable("access_ctlauth_task")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class AccessCtlauthTaskEntity
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        [SugarColumn(ColumnName = "taskId", IsPrimaryKey = true)]
        public string TaskId { get; set; }
        
        /// <summary>
        /// 控制器Id
        /// </summary>
        [SugarColumn(ColumnName = "ctlId")]        
        public string CtlId { get; set; }
        
        /// <summary>
        /// 控制器SN
        /// </summary>
        [SugarColumn(ColumnName = "ctlSN")]        
        public string CtlSn { get; set; }
        
        /// <summary>
        /// 门号  1,2,3,4
        /// </summary>
        [SugarColumn(ColumnName = "door1No")]        
        public int? Door1No { get; set; }
        
        /// <summary>
        /// 门号  1,2,3,4
        /// </summary>
        [SugarColumn(ColumnName = "door2No")]        
        public int? Door2No { get; set; }
        
        /// <summary>
        /// 门号  1,2,3,4
        /// </summary>
        [SugarColumn(ColumnName = "door3No")]        
        public int? Door3No { get; set; }
        
        /// <summary>
        /// 门号  1,2,3,4
        /// </summary>
        [SugarColumn(ColumnName = "door4No")]        
        public int? Door4No { get; set; }
        
        /// <summary>
        /// 权限用户
        /// </summary>
        [SugarColumn(ColumnName = "EmployeeId")]        
        public string EmployeeId { get; set; }
        
        /// <summary>
        /// 工号
        /// </summary>
        [SugarColumn(ColumnName = "JobNo")]        
        public string JobNo { get; set; }
        
        /// <summary>
        /// 姓名
        /// </summary>
        [SugarColumn(ColumnName = "ReallName")]        
        public string ReallName { get; set; }
        
        /// <summary>
        /// 部门Id
        /// </summary>
        [SugarColumn(ColumnName = "DepartId")]        
        public string DepartId { get; set; }
        
        /// <summary>
        /// 部门
        /// </summary>
        [SugarColumn(ColumnName = "DepartName")]        
        public string DepartName { get; set; }
        
        /// <summary>
        /// 卡号
        /// </summary>
        [SugarColumn(ColumnName = "CardNo")]        
        public string CardNo { get; set; }
        
        /// <summary>
        /// 有效时长，开始
        /// </summary>
        [SugarColumn(ColumnName = "StartTime")]        
        public DateTime? StartTime { get; set; }
        
        /// <summary>
        /// 有效时长，截止
        /// </summary>
        [SugarColumn(ColumnName = "EndTime")]        
        public DateTime? EndTime { get; set; }
        
        /// <summary>
        /// 1 新增， 2 删除
        /// </summary>
        [SugarColumn(ColumnName = "addorDel")]        
        public int? AddorDel { get; set; }
        
        /// <summary>
        /// 最后下发时间
        /// </summary>
        [SugarColumn(ColumnName = "lastIssueTime")]        
        public DateTime? LastIssueTime { get; set; }
        
        /// <summary>
        /// 下发次数
        /// </summary>
        [SugarColumn(ColumnName = "Issues")]        
        public int? Issues { get; set; }
        
        /// <summary>
        /// 创建用户
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserId")]        
        public string CreatorUserId { get; set; }
        
        /// <summary>
        /// 创建用户姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserName")]        
        public string CreatorUserName { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "CreatorTime")]        
        public DateTime? CreatorTime { get; set; }      
        
        /// <summary>
        /// 所在区域Id
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaId")]        
        public string DoorAreaId { get; set; }
        
        /// <summary>
        /// 所在区域名称
        /// </summary>
        [SugarColumn(ColumnName = "doorAreaName")]        
        public string DoorAreaName { get; set; }
        
        /// <summary>
        /// 门禁位置
        /// </summary>
        [SugarColumn(ColumnName = "ctlposition")]        
        public string Ctlposition { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "dbDate")]        
        public DateTime? DbDate { get; set; }
        
        /// <summary>
        /// 任务状态 0待执行 1已提取，执行中 2执行成功 3执行失败
        /// </summary>
        [SugarColumn(ColumnName = "taskStatus")]        
        public int? TaskStatus { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "strResult")]        
        public string StrResult { get; set; }
        
        /// <summary>
        /// 任务类型 1门禁权限 2门禁设置
        /// </summary>
        [SugarColumn(ColumnName = "taskType")]        
        public int? TaskType { get; set; }

        /// <summary>
        /// 删除标志
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteMark")]
        public int? DeleteMark { get; set; }

        /// <summary>
        /// 删除时间
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteTime")]
        public DateTime? DeleteTime { get; set; }

        /// <summary>
        /// 删除用户
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteUserId")]
        public string DeleteUserId { get; set; }

        /// <summary>
        /// 删除用户
        /// </summary>
        [SugarColumn(ColumnName = "F_DeleteUserName")]
        public string DeleteUserName { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }

        /// <summary>
        /// 是否彻底删除权限 0否1是
        /// </summary>
        [SugarColumn(ColumnName = "IsDeleteTask")]
        public int IsDeleteTask { get; set; }
        /// <summary>
        /// 控制器名称
        /// </summary>
        [SugarColumn(ColumnName = "ctlName")]
        public string ctlName { get; set; }
        

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.TaskId = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            this.DeleteMark = 0;
            this.TaskType = 1;
            this.TaskStatus = 0;
            this.DbDate = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public virtual void Delete()
        {
            this.DeleteMark = 1;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.DeleteTime = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.DeleteUserId = userId;
                this.DeleteUserName = userName;
            }
        }
    }
}